﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Text;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace HML.Demo
{
    public partial class DropDownListPlusForm : ItemFormTemplate
    {
        public DropDownListPlusForm()
        {
            InitializeComponent();
            this.Load += new System.EventHandler(this.Form_Load);
            this.Shown += new System.EventHandler(this.Form_Shown);
        }

        #region 实现

        public override ItemFormTemplateViewObject AsynchRequestTask(ItemFormTemplateViewObject view)
        {
            System.Threading.Thread.Sleep(300);
            view.ViewData = DemoHelper.GetDescription(AppDomain.CurrentDomain.BaseDirectory + "例子\\控件\\DropDownListPlusForm\\DropDownListPlusForm.rtf");
            return view;
        }

        public override void DataBind(ItemFormTemplateViewObject viewObject)
        {
            this.introduceBrowser.Rtf = viewObject.ViewData.ToString();
        }

        public override void ShowView()
        {
            base.ShowView();
        }

        public override void HideView()
        {
            base.HideView();
        }

        public override void CloseView()
        {
            base.CloseView();
        }

        #endregion

        #region 属性面板

        private void Form_Load(object sender, EventArgs e)
        {
            this.controlContainer.SizeChanged += this.ControlContainer_SizeChanged;

            this.demo_control.RoundEnabled = true;
            this.demo_control.ReadOnly = false;
            this.demo_control.DropDownButton.OperateFullArea = false;
            this.demo_control.ClearButtonVisible = false;
            this.demo_control.Multiple = false;
            this.demo_control.Content.Item.ClearButtonVisible = false;
            this.demo_control.Picker.LocateVisible = false;
            this.demo_control.Picker.Item.Icon.Visible = false;
            this.demo_control.Picker.StylePattern = DropDownListPlusPickerStylePattern.GradualLine;
            string[] textArr = DemoHelper.GetLists();
            DropDownListPlusItemCollection list = new DropDownListPlusItemCollection();
            for (int i = 0; i < textArr.Length; i++)
            {
                list.Add(new DropDownListPlusItem() { Text = textArr[i], Image = global::HML.Demo.Properties.Resources.Control_DropDownListPlus_ItemIco });
            }
            this.demo_control.BindItemsSource(list);

            this.roundEnabled_toggleSwitch.IsOn = this.demo_control.RoundEnabled;
            this.roundEnabled_toggleSwitch.Toggled += this.RoundEnabled_toggleSwitch_Toggled;

            this.readOnly_toggleSwitch.IsOn = this.demo_control.ReadOnly;
            this.readOnly_toggleSwitch.Toggled += this.ReadOnly_toggleSwitch_Toggled;

            this.dropDownFullArea_toggleSwitch.IsOn = this.demo_control.DropDownButton.OperateFullArea;
            this.dropDownFullArea_toggleSwitch.Toggled += this.OperateFullArea_toggleSwitch_Toggled;

            this.clearButtonVisible_toggleSwitch.IsOn = this.demo_control.Content.Item.ClearButtonVisible;
            this.clearButtonVisible_toggleSwitch.Toggled += this.ClearButtonVisible_toggleSwitch_Toggled;

            this.multiple_toggleSwitch.IsOn = this.demo_control.Multiple;
            this.multiple_toggleSwitch.Toggled += this.Multiple_toggleSwitch_Toggled;

            this.itemClearButtonVisible_toggleSwitch.IsOn = this.demo_control.Content.Item.ClearButtonVisible;
            this.itemClearButtonVisible_toggleSwitch.Toggled += this.Content_Item_ClearButtonVisible_toggleSwitch_Toggled;

            this.style_dropDownListPlus.Multiple = false;
            this.style_dropDownListPlus.BindEnumList<DropDownListPlusPickerStylePattern>(this.demo_control.Picker.StylePattern);
            this.style_dropDownListPlus.SelectedItemsChanged += this.Picker_StylePattern_dropDownListPlus_SelectedItemsChanged;

            this.locateVisible_toggleSwitch.IsOn = this.demo_control.Picker.LocateVisible;
            this.locateVisible_toggleSwitch.Toggled += this.Picker_LocateVisible_toggleSwitch_Toggled;

            this.itemimageVisible_toggleSwitch.IsOn = this.demo_control.Picker.Item.Icon.Visible;
            this.itemimageVisible_toggleSwitch.Toggled += this.Picker_Item_Icon_Visible_toggleSwitch_Toggled;
        }

        private void Form_Shown(object sender, EventArgs e)
        {
            this.splitContainer.SplitterDistance = Math.Max(this.splitContainer.Width / 4, this.splitContainer.Width - MainForm.GlobalSplitWidth);
            this.splitContainer.SplitterMoved += this.SplitContainer_SplitterMoved;

            MainForm.LoadAssistTabControl(this.assistTabControl);
        }

        private void SplitContainer_SplitterMoved(object sender, SplitterEventArgs e)
        {
            SplitContainer control = (SplitContainer)sender;
            MainForm.GlobalSplitWidth = this.splitContainer.Width - control.SplitterDistance;
        }

        private void ControlContainer_SizeChanged(object sender, EventArgs e)
        {
            Panel control = (Panel)sender;
            this.demo_control.Width = Math.Min(350, control.Width - 40);
            this.demo_control.Location = new Point((control.Width - this.demo_control.Width) / 2, (control.Height - this.demo_control.Height) / 2);
        }

        private void RoundEnabled_toggleSwitch_Toggled(object sender, EventArgs e)
        {
            ToggleSwitch control = (ToggleSwitch)sender;
            this.demo_control.RoundEnabled = control.IsOn;
        }

        private void ReadOnly_toggleSwitch_Toggled(object sender, EventArgs e)
        {
            ToggleSwitch control = (ToggleSwitch)sender;
            this.demo_control.ReadOnly = control.IsOn;
        }

        private void OperateFullArea_toggleSwitch_Toggled(object sender, EventArgs e)
        {
            ToggleSwitch control = (ToggleSwitch)sender;
            this.demo_control.DropDownButton.OperateFullArea = control.IsOn;
        }

        private void ClearButtonVisible_toggleSwitch_Toggled(object sender, EventArgs e)
        {
            ToggleSwitch control = (ToggleSwitch)sender;
            this.demo_control.ClearButtonVisible = control.IsOn;
        }

        private void Multiple_toggleSwitch_Toggled(object sender, EventArgs e)
        {
            ToggleSwitch control = (ToggleSwitch)sender;
            this.demo_control.Multiple = control.IsOn;
        }

        private void Content_Item_ClearButtonVisible_toggleSwitch_Toggled(object sender, EventArgs e)
        {
            ToggleSwitch control = (ToggleSwitch)sender;
            this.demo_control.Content.Item.ClearButtonVisible = control.IsOn;
        }

        private void Picker_StylePattern_dropDownListPlus_SelectedItemsChanged(object sender, EventArgs e)
        {
            DropDownListPlus control = (DropDownListPlus)sender;
            this.demo_control.Picker.StylePattern = (DropDownListPlusPickerStylePattern)control.SelectedItem.Tag;
        }

        private void Picker_LocateVisible_toggleSwitch_Toggled(object sender, EventArgs e)
        {
            ToggleSwitch control = (ToggleSwitch)sender;
            this.demo_control.Picker.LocateVisible = control.IsOn; 
        }

        private void Picker_Item_Icon_Visible_toggleSwitch_Toggled(object sender, EventArgs e)
        {
            ToggleSwitch control = (ToggleSwitch)sender;
            this.demo_control.Picker.Item.Icon.Visible = control.IsOn; 
        }

        #endregion

    }
}
